---------------------------------------------------------------
File name   :  vv_ahblite_monitor_h.e
Title       :  Bus monitors declaration and agent monitors
Project     :  vv_ahblite eVC
Developers  :  stefan,filip
Created     :  29.07.2011.

Description :  This file declares the bus monitor and agent monitor units.
    :  The bus monitor monitors activity from multiple agents
    :  on the bus, while the agent monitor monitors only
    :  activity for a specific agent.
    :  The advantage of using a bus monitor is that it improves
    :  performance, since there is only one process that
    :  probes the bus, instead of multiple processes (for each agent).

Notes       :  In our implementation we use both bus monitor and agent monitor.
    :  Collecting and constructing of the data-item from the bus
    :  is done once by the bus monitor and then the data-item
    :  is transferred to the specific agent monitor.
---------------------------------------------------------------
Copyright  (c)2011
---------------------------------------------------------------

<'
package vv_ahblite;

-- This is the method type for scoreboard hooks.
method_type transaction_complete_t(transaction : MONITOR vv_ahblite_transaction);

-- ==========================================================================
-- Bus monitor unit. It monitors all activity on the bus and collects 
-- information on each item that occurs.
-- ==========================================================================
extend vv_ahblite_bus_monitor {

    env_name : vv_ahblite_env_name_t;
    p_env : vv_ahblite_env;
    p_smp      : vv_ahblite_smp;
    p_sys_smp     : vv_ahblite_system_smp; 
    package !current_master : vv_ahblite_agent;
    package !current_slave : vv_ahblite_agent;

    -- This field determines the name of the bus monitor log file 
    -- (default: vv_ahblite.elog). If this field is 
    -- empty, the bus monitor will not write a log file.
    log_filename : string;
       keep soft log_filename == "vv_ahblite";
    has_checks : bool;
    has_coverage : bool;
       keep soft has_coverage;
    !transaction_delay_start : uint;
    !response_delay_start : uint;

    -- Current monitored transaction.
    !transaction : MONITOR'transaction_kind vv_ahblite_transaction;
    !num_transactions : uint; --do not constrain
      
    -- The following are useful events provided by the bus monitor. Note that
    -- these events are only declared here. The actual implementation of
    -- these events is in the file vv_ahblite_bus_monitor.e
         
    -- This event is emitted by the monitor 
    -- at the beginning of a transaction
    event transaction_start;
    
    -- This event is emitted by the monitor 
    -- at the completion of a request transaction
    event transaction_end;
    
    --Last transaction when the end of a burst is detected
    !previous_transaction : vv_ahblite_transaction;
    --Transfer that is finished
    !last_transfer: vv_ahblite_transaction;
    -------------------
    event burst_end;  --used for coverage
    event transfer_end;  --used for coverage
    event trans_change; -- used for coverage, when h_trans changed during wait state
    -------------------------
    -- true if there was an idle transaction 
    idle_emitted : bool ;
	keep idle_emitted == FALSE;
	-- true if there is a burst in progress
	in_burst : bool ;
	keep in_burst == FALSE;
	-- number of wait states in a burst
	wait_states_num: uint;
	keep wait_states_num == 0;
	--number of busy transfers in a burst
	busy_num: uint;
	keep busy_num == 0;
    
    event reset_start is @p_sys_smp.reset_start;
    -- This event gets emitted when reset is de-asserted.
    event reset_end is @p_sys_smp.reset_end;

    on reset_start {
        reset_start();
    };
    
    on reset_end {
        reset_end();
    };

    reset_start() is {
        message(LOW,"Start Reset...");
        previous_transaction = NULL;
        last_transfer = NULL;
        rerun();
    };

    reset_end() is {
        message(LOW,"Reset End...");
    };  
    -- This method port is the scoreboard hook for the monitor. This
    -- method port will be called at the completion of each transaction
    -- on the bus. 
    -- Note that the scoreboard hook is bound to empty so that no error
    -- is issued if the hook is not in use.
    transaction_complete : out method_port of transaction_complete_t is instance;
        keep bind (transaction_complete, empty);

    bus_mon_vt_style: vt_style;
       keep soft bus_mon_vt_style == GRAY;

    bus_mon_message_name : string;
       keep soft bus_mon_message_name == "BUS_MON";

    short_name(): string is {
        result = bus_mon_message_name;
    };

    short_name_style(): vt_style is {
       result = bus_mon_vt_style;
    };

};

'>
<'
-- ==========================================================================
-- Agent monitor unit. The agent monitor (used in masters and
-- slaves) filters the information collected by the bus monitor
-- to select the transactions handled by a specific agent.
-- ==========================================================================
extend vv_ahblite_agent_monitor {
    agent_name : vv_ahblite_agent_name_t;
    env_name:   vv_ahblite_env_name_t;
    p_env : vv_ahblite_env;
    !p_bus_monitor : vv_ahblite_bus_monitor;
    p_agent : vv_ahblite_agent;
    has_checks : bool;
    has_coverage : bool;
    !transaction : MONITOR vv_ahblite_transaction;
    !num_transactions : uint;
    !wait_states_num : uint;
    !busy_num : uint;
    
    -- This event is emitted with transaction_complete()
    -- It can be used in conjunction with the transaction field
    -- to provide an alternative scoreboard hook.
    event transaction_end;
    
    ---------------------------
    event burst_end;  --used for coverage
    event transfer_end;  --used for coverage
    event trans_change; -- used for coverage, when h_trans changed during wait state
    --------------------------  
    --Last transaction when the end of a burst is detected
    !previous_transaction : vv_ahblite_transaction;
    --Transfer that is finished
    !last_transfer: vv_ahblite_transaction;

    
    -- This method port     is the scoreboard hook for the monitor. This
    -- method port will be called at the completion of each transaction
    -- on the bus. 
    -- Note that the scoreboard hook is bound to empty so that no error
    -- is issued if the hook is not in use.
    transaction_complete : out method_port of transaction_complete_t is instance;
        keep bind (transaction_complete, empty);
    
    -- This method can be extended to initiate the agent monitor unit.
    -- It is called each time run() is called.   
    init_values() is empty;  
    
    reset_start() is {
        rerun();
    };
    reset_end() is empty;

    agent_mon_vt_style: vt_style;
       keep soft agent_mon_vt_style == GRAY;

    agent_mon_message_name : string;
       keep soft agent_mon_message_name == "AGENT_MON";

    short_name(): string is {
        result = append(agent_mon_message_name,"_",agent_name);
    };

    short_name_style(): vt_style is {
       result = agent_mon_vt_style;
    }; 
};

-- ==========================================================================
-- A monitor that watches a specific master's behavior
-- ==========================================================================
unit vv_ahblite_master_monitor like vv_ahblite_agent_monitor {};

-- ==========================================================================
-- A monitor that watches a specific slave's behavior
-- ==========================================================================
unit vv_ahblite_slave_monitor like vv_ahblite_agent_monitor {};
'>
